package com.person.commons.utils;

import java.util.List;

public class StringUtils {
	
	/**
	 * 将文件大小的数值形式转换成字符形式
	 * @param length
	 * @return
	 */
	public static String lengthToSize(long length){
		if(length <= 0){
			return "0B";
		}else if(length > 0 && length < 1024){
			return length + "B";
		}else if(length >= 1024 && length < 1024 * 1024){
			return (length * 100 / 1024 / 100.0) + "KB";
		}else{
			return (length * 100 / 1024 / 1024 / 100.0) + "MB";
		}
	}
	
	/**
	 * 将一个字符串数组转换成用户sql的字符窜
	 * @param emailIds
	 * @return
	 */
	public static String arrayToString(String[] ids){
		StringBuffer buffer = new StringBuffer();
		for(String id:ids){
			buffer.append("'" + id + "',");
		}
		if(buffer.length() > 0){
			return buffer.substring(0,buffer.length() - 1);
		}else{
			return buffer.toString();
		}
	}

	public static String ListToString(List<String> msgUids) {
		StringBuffer buffer = new StringBuffer();
		for(String id:msgUids){
			buffer.append("'" + id + "',");
		}
		if(buffer.length() > 0){
			return buffer.substring(0,buffer.length() - 1);
		}else{
			return buffer.toString();
		}
	}
}
